<!-- Advance table -->
<script src="<?= $url_styles ?>js/plugins/tables/jquery.dataTables.min.js"></script>
<script src="<?= $url_styles ?>js/plugins/tables/colResizable-1.3.min.js"></script>
<script src="<?= $url_styles ?>js/plugins/tables/jquery.tablesorter.min.js"></script> 

<script src="<?= $url_styles ?>js/plugins/formselements/jquery.ibutton.min.js"></script>  
<script src="<?= $url_styles ?>js/plugins/formselements/ui.spinner.min.js"></script> 
<script>
	var page = 1;
	function load_table()
	{
		$.ajax({
			url: '<?= url_create('admin', 'order_o', 'read') ?>',
			dataType: 'json',
			type: 'post',
			data: {p: page <?= isset($product) ? ', id: ' . $product->id : '' ?>},
			success: function(o)
			{
				if (o.state == 'success') {
					var str = '';
					for (var i in o.data) {
						var r = o.data[i];
						var row_class = (o.data[i].cancel == 1) ? 'X' : 'A';
						if (i % 2 == 1)
							row_class += " odd";
						else
							row_class += " even"
						str += '<tr id="row_' + r.id + '" class="grade' + row_class + '">' +
								'<td>' + r.fullname + '<br/>' + r.mobile + '<br/>' + r.address + '</td>' +
								'<td>' + r.total_orders + '</td>' +
								'<td class="center"><a href="' + r.detail_link + '" class="btn btn-mini btn-success row_edit"><?= lang('confirm') ?></a>' +
								'</tr>';
					}
					if (typeof(oTable) != 'undefined')
						oTable.fnDestroy();
					$('#table tbody').html(str);
					var p = o.pagination;
					var pnumbers = p.left ? '...' : '';
					for (var i in p.pnumbers) {
						var clas = p.pnumbers[i] == p.curr ? 'active' : 'button';
						pnumbers += '<a data="' + p.pnumbers[i] + '" class="paginate_' + clas + '">' + p.pnumbers[i] + '</a>';
					}
					if (p.right)
						pnumbers += '...';
					$('#table_paginate span').html(pnumbers);
					$('#table_previous').attr('data', p.prev);
					$('#table_next').attr('data', p.next);
					$('#table_first').attr('data', p.first);
					$('#table_last').attr('data', p.last);

				}
			}
		});
	}
	$('#table_paginate a').live('click', function(e) {
		var p = $(this).attr('data');
		if (p != null) {
			page = p;
			load_table();
		}
	});

	$(document).ready(load_table());
</script>
